import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';

void main() {
  return runApp(new TextFiled());
}

class TextFiled extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new TextFiledTest(),
    );
  }
}

class TextFiledTest extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return TextFiledState();
  }
}

class TextFiledState extends State<TextFiledTest> {
  TextEditingController _controller;

  @override
  void initState() {
    _controller = new TextEditingController();
    _controller.addListener(() {
      print("文本值 ${_controller.text}");
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Padding(
      padding: EdgeInsets.all(20),
      child: Container(
        width: 200,
        height: 50,
        child: TextField(
          keyboardType: TextInputType.phone,
          controller: _controller,
          textAlign: TextAlign.center,
          textInputAction:TextInputAction.done ,
          inputFormatters: [LengthLimitingTextInputFormatter(5)],
          // cursorColor: Colors.red,
          // cursorRadius: Radius.circular(16.0),
          // cursorWidth: 16.0,
          onSubmitted: (content) {
            Fluttertoast.showToast(msg: "提交的内容是$content");
          },
          decoration: InputDecoration(
              prefixIcon: Icon(Icons.search),
              suffixIcon: Icon(Icons.keyboard_voice),
              fillColor: Colors.white,
              filled: true,
              border: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(5),
              )),
        ),
      ),
    ));
  }
}
